﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace FileEncryption
{
    public static class FileEncryptioner
    {
        private static readonly int BUFFER_SIZE = 4096;

        public static void Encrypt(string fileName)
        {
            using (FileStream fs = new FileStream(@"..\..\" + fileName,
                FileMode.Open, FileAccess.ReadWrite, FileShare.None))
            {
                byte[] buf = new byte[BUFFER_SIZE];
                while (true)
                {
                    int bytesRead = fs.Read(buf, 0, buf.Length);
                    if (bytesRead == 0)
                    {
                        break;
                    }

                    fs.Seek(-bytesRead, SeekOrigin.Current);
                    fs.Write(buf, 0, bytesRead);
                }
            }
        }
    }
}
